package cn.aiweiyi.qingjing.coupon.template.converter;

import cn.aiweiyi.qingjing.coupon.comm.constant.CouponCategory;

import javax.persistence.AttributeConverter;
import javax.persistence.Convert;

/**
 * @author 青衿
 * @Date 2020/11/17 9:18
 * 优惠券分类的枚举转换器
 * JAP在执行CRUD时会分别调用其中两个方法
 **/
@Convert
public class CouponCategoryConverter implements AttributeConverter<CouponCategory, String> {
    @Override
    public String convertToDatabaseColumn(CouponCategory couponCategory) {
        return couponCategory.getCode();
    }

    @Override
    public CouponCategory convertToEntityAttribute(String code) {
        return CouponCategory.of(code);
    }
}
